package com.zc.study;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * common loop example
 */
public class LoopExample {
    private final static Logger logger = LoggerFactory.getLogger(LoopExample.class);

    //map Loop:同时操作key value
    public static void mapLoop(Map<String, String> map) {
        for (Map.Entry<String, String> param : map.entrySet()) {
            logger.debug("key::,{},value::,{}", param.getKey(), param.getValue());
        }
    }

    //date loop
    public static void dateLoop(Date startTime, Date endTime, List<Date> list) {
        Calendar start = Calendar.getInstance();
        start.setTime(startTime);
        Calendar end = Calendar.getInstance();
        end.setTime(endTime);
        end.add(Calendar.DAY_OF_MONTH, 1);
        while (start.getTime().before(end.getTime())) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            if (list.contains(start.getTime())) {
                String str = sdf.format(start.getTime());
                logger.debug("当前日期::,{},在集合中",str);
            }
            //开始时间+1天
            start.add(Calendar.DAY_OF_MONTH, 1);
        }
    }
}
